﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QueuesAndStacks.MyQueue
{
    class MainProject
    {
        static void Main(string[] args)
        {
            int[] nums = new int[] { 1, 1, 1, 1, 1 };
            int target = 3;
            MyQueue myQueue = new MyQueue();
            myQueue.Push(1);
            myQueue.Push(2);
            myQueue.Peek();
            myQueue.Pop();
            myQueue.Empty();
            //Console.WriteLine(FindTargetSumWays(nums, target));
            Console.ReadKey();
        }
        public class MyQueue
        {
            private Dictionary<int, Stack<int>> m_Dic = new Dictionary<int, Stack<int>>();
            private int m_CurStackID = 0;
            public MyQueue()
            {
                for (int i = 0; i < 2; i++) m_Dic.Add(i, new Stack<int>());
            }

            public void Push(int x)
            {
                m_Dic[0].Push(x);
            }

            public int Pop()
            {
                Injection(m_Dic[0], m_Dic[1]);
                int value = m_Dic[1].Pop();
                Injection(m_Dic[1], m_Dic[0]);
                return value;
            }

            private static void Injection(Stack<int> stack1, Stack<int> stack2)
            {
                stack2.Clear();
                while (stack1.Any()) stack2.Push(stack1.Pop());
            }

            public int Peek()
            {
                Injection(m_Dic[0], m_Dic[1]);
                int peek = m_Dic[1].Peek();
                Injection(m_Dic[1], m_Dic[0]);
                return peek;
            }

            public bool Empty()
            {
                return m_Dic[0].Count == 0;
            }
        }
    }
}
